<?php
namespace service;

class Cipher
{
    const iv = '3D3|tE#u)-Wwg!70';

    const key = '2EFD8DFA6A4670C0';


    //encrypt_openssl新版加密
    public static function encrypt_openssl($data,$key=null,$iv=null)
    {
        $key = empty($key ) ? self::key : $key;
        $iv  = empty($iv )  ? self::iv  : $iv;
        $data = openssl_encrypt(trim($data), 'AES-128-CBC',$key,0,$iv);
        return $data;
    }

    //decrypt_openssl新版解密
    // options 0是pkcs5模式和pkcs7模式(加密结果是一样的)
    public static function decrypt_openssl($data,$key=null,$iv=null)
    {
        $key = empty($key ) ? self::key : $key;
        $iv  = empty($iv )  ? self::iv  : $iv;
        return trim(openssl_decrypt($data, 'AES-128-CBC', $key, 0, $iv));
    }

}